<template>
  <HomePanel title="热门品牌" sub-title="国际经典 品质保障" style="background-color:#f5f5f5">
    <template #right>
      <a href="javascript:;" class="iconfont icon-angle-left prev" @click="goLeft" :class="{grayBtn:pos===0}"></a>
      <a href="javascript:;" class="iconfont icon-angle-right" @click="goRight" :class="{grayBtn:pos===1240}"></a>
    </template>
    <template #main>
      <div class="box">
        <ul class="brand-list" :class="{move:pos===1240}">
          <li v-for="item in list" :key="item.id">
            <img v-imgLazy="item.picture" alt="">
          </li>
        </ul>
      </div>
    </template>
  </HomePanel>

</template>

<script>
import HomePanel from './homePanel'
import { findBrand } from '@/api/home'
import { ref } from 'vue'
export default {
  name: 'homePanel',
  components: {
    HomePanel
  },
  setup () {
    // 1.定义响应式数据
    const list = ref([])
    // 2.定义函数 函数内部调用接口函数
    async function getList () {
      const res = await findBrand()
      list.value = res.data.result
    }
    getList()
    // 定义滑动图片
    const pos = ref(0)
    function goLeft () {
      pos.value = 0
    }
    function goRight () {
      pos.value = 1240
    }
    return {
      list, pos, goLeft, goRight
    }
  }
}
</script>

<style scoped lang="less">
.iconfont {
  margin-right: 5px;
  width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  color: #fff;
  background-color: @xtxColor;

  &.grayBtn {
    background-color: #ccc;
    cursor: no-drop;
  }
}
.box {
  width: 1240px;
  overflow: hidden;
}
.brand-list {
  display: flex;
  justify-content: space-between;
  transition: all 1s;
  width: 2480px;

  &.move {
    transform: translateX(-1240px);
  }

  li {
    flex: 1;
    img {
      width: 240px;
      height: 100%;
    }
  }
}
</style>
